package adc.budget.impl.bs;

import java.util.Collections;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import adc.app.spec.IDao;
import adc.budget.spec.bo.IAccount;
import adc.budget.spec.bo.ICategory;
import adc.budget.spec.bo.ISource;
import adc.budget.spec.bs.ISourceBs;

import com.google.common.collect.Lists;

@Service
public class SourceBs implements ISourceBs {

    private IDao<ISource> dao;

    @Autowired
    public SourceBs(final IDao<ISource> dao) {
        super();
        this.dao = dao;
    }

    @Override
    public List<ISource> getDestinations() {
        final List<ISource> destinations = Lists.newArrayList();
        destinations.addAll(dao.list(IAccount.class, null, null, null, Collections.singletonMap("name", true)));
        destinations.addAll(dao.list(ICategory.class, Collections.singletonMap("income", (Object) Boolean.FALSE), null, null,
                Collections.singletonMap("name", true)));
        return destinations;
    }

    @Override
    public List<ISource> getSources() {
        final List<ISource> sources = Lists.newArrayList();
        sources.addAll(dao.list(IAccount.class, null, null, null, Collections.singletonMap("name", true)));
        sources.addAll(dao.list(ICategory.class, Collections.singletonMap("income", (Object) Boolean.TRUE), null, null,
                Collections.singletonMap("name", true)));
        return sources;
    }

}
